package com.hmall.item.constatns;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    @Bean
    public TopicExchange exchange(){
        return new TopicExchange(MqConstants.ITEM_EXCHANGE);
    }

    @Bean
    public Queue insertAndUpdateQueue(){
        return new Queue(MqConstants.ITEM_INSERT_QUEUE,true);
    }

    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstants.ITEM_DELETE_QUEUE,true);
    }

    @Bean
    public Binding insertAndUpdateBinding(){
        return BindingBuilder.bind(insertAndUpdateQueue()).to(exchange()).with(MqConstants.ITEM_INSERT_KEY);
    }

    @Bean
    public Binding deleteBinding(){
        return BindingBuilder.bind(deleteQueue()).to(exchange()).with(MqConstants.ITEM_DELETE_KEY);
    }

}
